package com.example.myapplication.activitys;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.myapplication.MainActivity;
import com.example.myapplication.R;
import com.example.myapplication.bean.SelectActivityBean;

import java.util.ArrayList;
import java.util.List;

public class SelectActivity extends BaseActivity {

    RecyclerView select_activity_rv;
    List<SelectActivityBean> beanList;

    BaseQuickAdapter<SelectActivityBean, BaseViewHolder> adapter;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select);
        initView();
        initDate();
        initAdapter();
    }

    private void initView() {
        select_activity_rv = findViewById(R.id.select_activity_rv);
        select_activity_rv.setLayoutManager(new LinearLayoutManager(this));
        select_activity_rv.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
    }

    private void initDate() {
        beanList = new ArrayList<>(20);
        beanList.add(new SelectActivityBean("746", "泰安"));
        beanList.add(new SelectActivityBean("128", "济南"));
        beanList.add(new SelectActivityBean("622", "日照"));
        beanList.add(new SelectActivityBean("170", "烟台"));
        beanList.add(new SelectActivityBean("480", "临沂"));
        beanList.add(new SelectActivityBean("656", "枣庄"));
        beanList.add(new SelectActivityBean("5", "青岛"));
        beanList.add(new SelectActivityBean("169", "威海"));
        beanList.add(new SelectActivityBean("360", "中国台北"));
        beanList.add(new SelectActivityBean("1", "北京"));
        beanList.add(new SelectActivityBean("2", "上海"));
        beanList.add(new SelectActivityBean("14", "杭州"));
        beanList.add(new SelectActivityBean("9", "南京"));
        beanList.add(new SelectActivityBean("154", "天津"));
        beanList.add(new SelectActivityBean("21", "厦门"));
        beanList.add(new SelectActivityBean("25", "九寨沟"));
        beanList.add(new SelectActivityBean("104", "成都"));
        beanList.add(new SelectActivityBean("7", "西安"));
        beanList.add(new SelectActivityBean("152", "广州"));
        beanList.add(new SelectActivityBean("61", "三亚"));
    }

    private void initAdapter() {
        adapter = new BaseQuickAdapter<SelectActivityBean, BaseViewHolder>(R.layout.item_select_activity, beanList) {
            @Override
            protected void convert(BaseViewHolder helper, SelectActivityBean item) {
                helper.setText(R.id.item_secect_tv, item.getCityName());
            }
        };
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                MainActivity.CityCode = beanList.get(position).getCityCode();
                MainActivity.CityNmae = beanList.get(position).getCityName();
                Toast.makeText(SelectActivity.this, "您已选择" + beanList.get(position).getCityName(), Toast.LENGTH_SHORT).show();
                finish();
            }
        });
        select_activity_rv.setAdapter(adapter);
    }

}
